package glen.mgbean;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import java.io.Serializable;

/**
 * Created by rachatanawee on 4/10/2014.
 */
@ManagedBean(name = "currentUser")
@SessionScoped
public class CurrentUserMgb implements Serializable {
    public boolean checkPermission(String permissions) {
        boolean hadPerm = false;
        String[] permSplit = permissions.split(",");
        Subject currentUser = SecurityUtils.getSubject();

        try {
            hadPerm = currentUser.isPermittedAll(permSplit);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return hadPerm;
    }
}
